package calendar.commands.calendar;

import calendar.commands.ClientCommand;
import calendar.view.panels.CalendarGridPanel;
import com.google.api.services.calendar.model.Calendar;
import swing.Dialog;

import java.io.IOException;

public class CreateCalendar extends ClientCommand<Calendar> {
    private final Calendar entry = new Calendar();

    public CreateCalendar(com.google.api.services.calendar.Calendar client) {
        super(client);
    }

    public CreateCalendar setSummary(String summary) {
        entry.setSummary(summary);
        return this;
    }

    public void protectedExecute() throws IOException {
        Calendar result = client.calendars().insert(entry).execute();
        Dialog.popup(new CalendarGridPanel(result));
        setResult(result);
    }
}
